////////////////////////////////////////////////////////////////////////////////
// This file is part of the Mist compiler.                                    //
//                                                                            //
// Copyright (C) 2008, 2009 The Mist project                                  //
//                                                                            //
// For a list of contributors, see the COMMITTERS file.                       //
//                                                                            //
// The Mist compiler is free software: you can redistribute it and/or modify  //
// it under the terms of the GNU General Public License as published by       //
// the Free Software Foundation, either version 3 of the License, or          //
// (at your option) any later version.                                        //
//                                                                            //
// The Mist compiler is distributed in the hope that it will be useful,       //
// but WITHOUT ANY WARRANTY; without even the implied warranty of             //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              //
// GNU General Public License for more details.                               //
//                                                                            //
// You should have received a copy of the GNU General Public License          //
// in the COPYING file. If not, see <http://www.gnu.org/licenses/>.           //
////////////////////////////////////////////////////////////////////////////////

///
/// \file
/// The common/numeric.hpp test-suite.
///

////////////////////////////////////////////////////////////////////////////////
// Includes                                                                   //
////////////////////////////////////////////////////////////////////////////////

#include "common/numeric.hpp"
#include "test/common.hpp"

////////////////////////////////////////////////////////////////////////////////
// Test Cases                                                                 //
////////////////////////////////////////////////////////////////////////////////

BOOST_AUTO_TEST_SUITE( suite_common_numeric )
	
	BOOST_AUTO_TEST_CASE( test_max ) {
		BOOST_CHECK_EQUAL( max( 1,    2  ),  2   );
		BOOST_CHECK_EQUAL( max(-1,   -2  ), -1   );
		BOOST_CHECK_EQUAL( max( 0.1,  0.2),  0.2 );
		BOOST_CHECK_EQUAL( max(-0.1, -0.2), -0.1 );
	}
	
	BOOST_AUTO_TEST_CASE( test_digit_count ) {
		BOOST_CHECK_EQUAL( digit_count(1)          , 1 );
		BOOST_CHECK_EQUAL( digit_count(25)         , 2 );
		BOOST_CHECK_EQUAL( digit_count(931)        , 3 );
		BOOST_CHECK_EQUAL( digit_count(1234)       , 4 );
		BOOST_CHECK_EQUAL( digit_count(1234567890l), 10);
		
		BOOST_CHECK_THROW( digit_count(-5), AssertionFailure );
	}
	
	BOOST_AUTO_TEST_CASE( test_ordinal_indicator ) {
		BOOST_CHECK_EQUAL( ordinal_indicator( 1), "st" );
		BOOST_CHECK_EQUAL( ordinal_indicator( 2), "nd" );
		BOOST_CHECK_EQUAL( ordinal_indicator( 3), "rd" );
		BOOST_CHECK_EQUAL( ordinal_indicator( 4), "th" );
		BOOST_CHECK_EQUAL( ordinal_indicator( 5), "th" );
		
		BOOST_CHECK_EQUAL( ordinal_indicator(10), "th" );
		BOOST_CHECK_EQUAL( ordinal_indicator(11), "th" );
		BOOST_CHECK_EQUAL( ordinal_indicator(12), "th" );
		BOOST_CHECK_EQUAL( ordinal_indicator(13), "th" );
		BOOST_CHECK_EQUAL( ordinal_indicator(14), "th" );
		BOOST_CHECK_EQUAL( ordinal_indicator(15), "th" );
		
		BOOST_CHECK_EQUAL( ordinal_indicator(20), "th" );
		BOOST_CHECK_EQUAL( ordinal_indicator(21), "st" );
		BOOST_CHECK_EQUAL( ordinal_indicator(22), "nd" );
		BOOST_CHECK_EQUAL( ordinal_indicator(23), "rd" );
		BOOST_CHECK_EQUAL( ordinal_indicator(24), "th" );
		BOOST_CHECK_EQUAL( ordinal_indicator(25), "th" );
	}
	
	BOOST_AUTO_TEST_CASE( test_ordinal ) {
		BOOST_CHECK_EQUAL( ordinal( 1), "1st" );
		BOOST_CHECK_EQUAL( ordinal( 2), "2nd" );
		BOOST_CHECK_EQUAL( ordinal( 3), "3rd" );
		BOOST_CHECK_EQUAL( ordinal( 4), "4th" );
		BOOST_CHECK_EQUAL( ordinal( 5), "5th" );
		
		BOOST_CHECK_EQUAL( ordinal(10), "10th" );
		BOOST_CHECK_EQUAL( ordinal(11), "11th" );
		BOOST_CHECK_EQUAL( ordinal(12), "12th" );
		BOOST_CHECK_EQUAL( ordinal(13), "13th" );
		BOOST_CHECK_EQUAL( ordinal(14), "14th" );
		BOOST_CHECK_EQUAL( ordinal(15), "15th" );
		
		BOOST_CHECK_EQUAL( ordinal(20), "20th" );
		BOOST_CHECK_EQUAL( ordinal(21), "21st" );
		BOOST_CHECK_EQUAL( ordinal(22), "22nd" );
		BOOST_CHECK_EQUAL( ordinal(23), "23rd" );
		BOOST_CHECK_EQUAL( ordinal(24), "24th" );
		BOOST_CHECK_EQUAL( ordinal(25), "25th" );
	}
	
BOOST_AUTO_TEST_SUITE_END()
